﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using MySql.Data.MySqlClient;

namespace DAL
{
    public class integral_ruleDal
    {
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="merchantid"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static int Update(string merchantid, string amount)
        {
            string sql = "update ms_integral_rule set amount=@amount,update_time=@update_time where merchant_id=@merchant_id";
            MySqlParameter[] values = new MySqlParameter[3];
            values[0] = new MySqlParameter("amount", amount);
            values[1] = new MySqlParameter("update_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            values[2] = new MySqlParameter("merchant_id", merchantid);
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 0不存在
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static int Querybymerid(string merchantid)
        {
            string sql = "select * from ms_integral_rule where merchant_id=@merchant_id";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("merchant_id", merchantid);
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            int count = 0;
            if (rd.Read())
            {
                if (!string.IsNullOrEmpty(rd["amount"].ToString()))
                    count = Convert.ToInt32(rd["amount"]);
            }
            rd.Close();
            return count;
        }
        /// <summary>
        /// 添加规则
        /// </summary>
        /// <param name="merchantid"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static int Addreul(string merchantid, string amount)
        {
            string sql = "insert into ms_integral_rule(merchant_id,amount,update_time) values(@merchant_id,@amount,@update_time)";
            MySqlParameter[] values = new MySqlParameter[3];
            values[0] = new MySqlParameter("amount", amount);
            values[1] = new MySqlParameter("update_time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            values[2] = new MySqlParameter("merchant_id", merchantid);
            return DBHelper.ExcutUpdate(sql, values);
        }

    }
}
